package com.is.common.exception;

/**
 * @author Administrator
 * @date 2017/4/6 0006
 */

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
 * 异常发送类
 */

public class ExceptionSender {

    private Context context;

    private String url="你的收集异常信息的服务器的地址";
    //版本名称
    private String app_name;
    //版本号
    private String app_version;
    //设备名称
    private String device_name;
    //操作系统
    private String os_name;
    //操作系统版本号
    private String os_version;

    private ExecutorService cachedThreadPool = Executors.newCachedThreadPool();


    public ExceptionSender(Context context)
    {
        init(context);
        this.context = context;
    }

    private void init(Context context)
    {
        PackageInfo packInfo;
        try
        {
            packInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            if (packInfo != null)
            {
                app_name = packInfo.packageName;
                app_version = packInfo.versionName;
            }
            device_name = android.os.Build.MODEL;
            os_name = "Android";
            os_version = android.os.Build.VERSION.RELEASE;
        }
        catch (PackageManager.NameNotFoundException e)
        {
        }
    }

    /**
     * 发送错误信息到错误收集中心.
     *
     * @param ex
     */
    public void send(final Throwable ex)
    {
        LogToFileUtils.init(context);
        LogToFileUtils.write(ex);

    }
}
